<template>
	<view class="uptime" :style="{height: wh + 'px'}">
		<view class="time-box">
			<view class="top" @click="timeShow = true">
				<view class="left">工作时间</view>
				<view class="right">{{cleanerForm.works_times}}</view>
				<view class="icon">
					<u-icon name="arrow-right" color="#C0C0C0"></u-icon>
				</view>
			</view>
			<view class="bom">
				<block v-for="(item,i) in dayList" :key="i">
					<view :class="['day',{'dayaiv':aivindex == i}]" @click="doday(i,item)">{{item.value}}</view>
				</block>

			</view>
		</view>

		<!-- 底部 -->
		<view class="footer">
			<button class="btn" @click="upday">保存</button>
		</view>

		<!-- 弹层 -->
		<u-select v-model="timeShow" mode="mutil-column" :list="timeList" @confirm="confirm"></u-select>
	</view>
</template>

<script>
	import { timeList, dayList } from '@/untils/infodata.js'
	export default {
		data() {
			return {
				wh: '',
				timeShow: false,
				aivindex: 0,
				timeList: timeList,
				dayList: dayList,
				cleanerForm: {
					week: '', //周
					works_times: '06:00-06:00' // 时间
				}
			}
		},
		onShow() {
			// 获取页面可操作高度
			let getWindowInfo = uni.getWindowInfo()
			this.wh = getWindowInfo.windowHeight
		},
		methods: {
			upday() {
				if (!this.cleanerForm.week) return uni.$showMsg('请选择时间')
				if (!this.cleanerForm.works_times) return uni.$showMsg('请选择工作日')

				uni.$emit('uptime', this.cleanerForm)
				uni.navigateBack()
			},
			doday(i, item) {
				this.aivindex = i
				this.cleanerForm.week = item.value
				if (i == 0) {
					this.cleanerForm.week = '周一' + ',' + '周二' + ',' + '周三' + ',' + '周四' + ',' + '周五' + ',' + '周六' + ',' +
						'周日'
				}
			},
			confirm(e) {
				this.cleanerForm.works_times = e[0].label + '-' + e[1].label

			}
		}
	}
</script>

<style lang="scss" scoped>
	.uptime {
		padding: 20rpx 24rpx 0;
		background: #F7F7F7;

		.time-box {
			background: #FFFFFF;
			font-size: 26rpx;

			border-radius: 24rpx;
			padding: 55rpx 40rpx;

			.top {
				display: flex;
				justify-content: space-between;
				padding-bottom: 15rpx;
				border-bottom: 1rpx solid #F0EDED;
				position: relative;

				.left {
					font-weight: 600;
				}

				.right {
					margin-right: 50rpx;
				}

				.icon {
					position: absolute;
					top: 0;
					right: 0;
				}
			}

			.bom {

				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;

				.day {
					width: 140rpx;
					height: 62rpx;
					background: #F5F5F5;
					border-radius: 7rpx;
					text-align: center;
					line-height: 62rpx;
					margin-top: 20rpx;
				}

				.dayaiv {
					color: #fff;
					background-color: #01C3A8;
				}
			}
		}

		// 底部
		.footer {
			width: 100%;
			height: 128rpx;
			background-color: #fff;
			padding: 20rpx 0;
			z-index: 9;
			position: fixed;
			bottom: 0;
			left: 0;

			.btn {
				width: 676rpx;
				height: 84rpx;
				line-height: 84rpx;
				background-color: #01C3A8;
				color: #F3FFFE;
				font-size: 30rpx;
				border-radius: 42rpx;
			}

			button.btn::after {
				border: none;
			}
		}
	}
</style>
